package com.leetcode.dynamic_programming;

/**
 * @author Dennis Li
 * @date 2020/7/12 10:50
 */
public class ClimbStairs_70 {
    public int climbStairs(int n) {
        if (n <= 1) return 1;
        // 需要从最后跳到最前面
        // 通过变化问题f(n) = f(n - 1) + f(n - 2)
        // 通过两个变量来记录斐波拉契数列中n - 1和n - 2的位置的值
        int a = 1, b = 1, temp;
        for (int i = 2; i <= n; i++) {
            temp = a + b;
            a = b;
            b = temp;
        }
        return b;
    }
}
